﻿using FineAdmin.Common;
using FineAdmin.IService;
using FineAdmin.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace HuiJi.CMS.Blog.Controllers
{
    public class BaseController : Controller
    {
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {

            ViewBag.BlogPostsCategorieList = GetBlogPostsCategorieList();


            var TLD = Common.GetTopDomainName(Request.Url.Host);
            var TLDInfo = ICPLicenseService.GetByWhere(" where DomainName = '" + TLD + "'").FirstOrDefault();
            if (TLDInfo != null)
            {

                ViewBag.ICP = TLDInfo.ICP;
                ViewBag.GABEIAN = TLDInfo.PSNumber;
                ViewBag.GABEIANFULL = TLDInfo.PS;
            }
            else
            {
                ViewBag.ICP = SystemParameterService.GetByCode("ICP").SPValue;
                ViewBag.GABEIAN = SystemParameterService.GetByCode("GABEIAN").SPValue;//公安备案号 纯数字
                ViewBag.GABEIANFULL = SystemParameterService.GetByCode("GABEIANFULL").SPValue;//公安备案号 全名
            }
            

            ViewBag.EnableCommentSys = SystemParameterService.GetByCode("EnableCommentSys").SPValue;//是否启用评论留言功能
            base.OnActionExecuting(filterContext);
        }
        public IICPLicenseService ICPLicenseService { get; set; }
        public IBlogPostsCategorieService BlogPostsCategorieService { get; set; }

        public ISystemParameterService SystemParameterService { get; set; }

        public List<SystemParameterModel> GetSystemParameter()
        {

            return SystemParameterService.GetAll().ToList();
        }

        public List<BlogPostsCategorieModel> GetBlogPostsCategorieList()
        {
            return BlogPostsCategorieService.GetAll().ToList();
        }


        protected const string SuccessText = "操作成功！";
        protected const string ErrorText = "操作失败！";
        /// <summary>
        /// 操作成功
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        protected virtual AjaxResult SuccessTip(string message = SuccessText)
        {
            return new AjaxResult { state = ResultType.success.ToString(), message = message };
        }
        /// <summary>
        /// 操作失败
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        protected virtual AjaxResult ErrorTip(string message = ErrorText)
        {
            return new AjaxResult { state = ResultType.error.ToString(), message = message };
        }
    }
}